package com.eling.elcms.travel.webapp.controller;

import com.eling.elcms.basedoc.model.BusinessMessage;
import com.eling.elcms.basedoc.model.TargetType;
import com.eling.elcms.basedoc.model.TaskType;
import com.eling.elcms.basedoc.service.IBusinessMessageManager;
import com.eling.elcms.core.dao.hibernate.search.SearchCondition;
import com.eling.elcms.core.webapp.controller.BaseFormController;
import com.eling.elcms.core.webapp.controller.Msg;
import com.eling.elcms.core.webapp.spring.ModelFilling;
import com.eling.elcms.travel.model.PlanItemGroup;
import com.eling.elcms.travel.model.PlanItemGroup.SignUpStatus;
import com.eling.elcms.travel.model.view.AdjustGroupView;
import com.eling.elcms.travel.model.view.PlanItemGView;
import com.eling.elcms.travel.model.view.PlanItemGroupView;
import com.eling.elcms.travel.service.IPlanItemGroupManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class PlanItemGroupController extends BaseFormController{

	@Autowired
	private IPlanItemGroupManager planItemGroupManager;
	@Autowired
	private IBusinessMessageManager businessMessageManager;
	
	@RequestMapping("/api/planitemgroup/save")
    @ResponseBody
	public PlanItemGroup save(@ModelAttribute@ModelFilling PlanItemGroup cond){
		return planItemGroupManager.save(cond);
	}
	
	@RequestMapping("/api/planitemgroup/{pkPlanItemGroup}/delete")
	@ResponseBody
	public Msg delete(@PathVariable Long pkPlanItemGroup){
		planItemGroupManager.remove(pkPlanItemGroup);
		return new Msg("删除成功");
	}
	
	@RequestMapping("/api/planitemgroup/query")
    @ResponseBody
	public List<PlanItemGroup> query(@ModelAttribute PlanItemGroup cond){
		return planItemGroupManager.query(cond);
	}
	
	@RequestMapping("/api/planitemgroup/search*")
	@ResponseBody
	public List<PlanItemGroup> search(@ModelAttribute SearchCondition sc,@ModelAttribute PlanItemGroup cond){
		sc.setQueryCondition(cond);
		return planItemGroupManager.search(sc);
	}
	
	/**
	 * 收费完成后复核
	 * @param pkPlanItemGroup
	 * @author zhoulin
	 */
	@RequestMapping("/api/planitemgroup/reviewplanitemgroup")
	@ResponseBody
	public PlanItemGroup reviewPlanItemGroup(
			@RequestParam(value = "pkPlanItemGroup", required = false) Long pkPlanItemGroup) {
		PlanItemGroup planItemGroup = planItemGroupManager.get(pkPlanItemGroup);
		planItemGroup.setSignUpStatus(SignUpStatus.Review);
		businessMessageManager.saveBusinessMessage(new BusinessMessage(TargetType.Role,TaskType.GroupReserve,planItemGroup.getPkPlanItemGroup()));
		return planItemGroupManager.save(planItemGroup);
	}
	
	/**
	 * 收费完成后复核（调整后）
	 * @param pkPlanItemGroup
	 * @author linjizeng
	 */
	@RequestMapping("/api/planitemgroup/reviewplanitem")
	@ResponseBody
	public PlanItemGroup reviewPlanItem(
			@RequestParam(value = "pkPlanItemGroup", required = false) Long pkPlanItemGroup) {
		PlanItemGroup planItemGroup = planItemGroupManager.get(pkPlanItemGroup);
		planItemGroup.setSignUpStatus(SignUpStatus.AdjustmentReview);
		businessMessageManager.saveBusinessMessage(new BusinessMessage(TargetType.Role,TaskType.GroupReserve,planItemGroup.getPkPlanItemGroup()));
		return planItemGroupManager.save(planItemGroup);
	}
	
	/**
	 * 入住调整保存接口
	 * @param view
	 * @return
	 * @author zhoulin
	 */
	@RequestMapping("/api/planitemgroup/saveadjust")
	@ResponseBody
	public AdjustGroupView saveAdjust(@ModelAttribute AdjustGroupView view) {
		return planItemGroupManager.saveAdjust(view);
	}
	
	/**
	 * 报名退费查询接口
	 * @param cond
	 * @return
	 */
	@RequestMapping("/api/planitemgroup/queryrefund")
	@ResponseBody
	public List<PlanItemGroupView> querySignUpRefund(@ModelAttribute PlanItemGroup cond){
		return planItemGroupManager.querySignUpRefund(cond);
	}
	
	/**
	 * 整团取消。。老人团
	 * @param cond
	 * @return
	 * @author zhoulin
	 */
	@RequestMapping("/api/planitemgroup/cancelgroup")
    @ResponseBody
	public PlanItemGroup cancelGroup(@ModelAttribute@ModelFilling PlanItemGroup cond){
		return planItemGroupManager.cancelGroup(cond);
	}
	
	@RequestMapping("/api/planitemgroup/saveroomtype")
    @ResponseBody
	public PlanItemGroup saveRoomType(@ModelAttribute PlanItemGView cond){
		return planItemGroupManager.saveRoomType(cond);
	}
	
}
